package com.ypan.creator;

/**
 * Author ypan
 * Date on 2021/3/8  16:27
 * Desc 简单工厂设计模式：告诉对方需要创建什么对象
 */
public class EasyBallFactory {

    interface Ball{
        String create();
    }

    static class Soccer implements Ball{

        public String create() {
            return "give you a soccer";
        }
    }

    static class BasketBall implements Ball{

        public String create() {
            return "give you a BasketBall";
        }
    }

    public static Ball createBall(String name){
        if("Soccer".equals(name)){
            return new Soccer();
        }else{
            return new BasketBall();
        }
    }

    public static void main(String[] args) {
        Ball soccer = createBall("Soccer");
        System.out.println(soccer.create());
    }
}
